package study.dq.jms.filter;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author dongqun
 * @version 1.0
 * @description 类的功能描述
 * @date 2019/11/22 16:47
 */
public class DOD implements MessageListener {

    public DOD() {
        try {
            ConnectionFactory factory = new ActiveMQConnectionFactory("admin","admin","tcp://127.0.0.1:61616");
            QueueConnection connection = ((ActiveMQConnectionFactory) factory).createQueueConnection();
            QueueSession session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
            Queue queue = session.createQueue("Combat_Intelligence");
            String filter = "COMBAT_LEVEL = 2";
            QueueReceiver receiver = session.createReceiver(queue,filter);
            receiver.setMessageListener(this);
            connection.start();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onMessage(Message message) {
        try {
            TextMessage textMessage = (TextMessage) message;
            System.out.println("收到指令："+textMessage.getText());
            System.out.println("国防部二厅分析战报......");
            System.out.println("国防部命令：福建省二级战备，准备收复台湾");
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        DOD cmc = new DOD();
    }
}
